﻿using hyjx.bind;
using FeedingReport.Commands;
using Microsoft.EntityFrameworkCore.Query;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FeedingReport.Models
{
    /// <summary>
    /// 分页器模型
    /// </summary>
    public class PagorModel : BindableBase
    {
        /// <summary>
        /// 创建一个新的分页器模型
        /// </summary>
        public PagorModel()
        {
            PageRows.Add(50, 50.ToString());
            PageRows.Add(100, 100.ToString());
            PageRows.Add(200, 200.ToString());
            PageRows.Add(500, 500.ToString());

            SelectedPageRows = PageRows.First(p => p.Key == 100);
        }

        public Dictionary<int, string> PageRows { get; } = new Dictionary<int, string>();

        private KeyValuePair<int, string> _selectedPageRows;
        /// <summary>
        /// 选中的页行数
        /// </summary>
        public KeyValuePair<int,string> SelectedPageRows { get => _selectedPageRows; set => SetProperty(ref _selectedPageRows, value); }

        private int _currentPageNumber;
        /// <summary>
        /// 当前页号
        /// </summary>
        public int CurrentPageNumber { get => _currentPageNumber; set => SetProperty(ref _currentPageNumber, value); }

        private int _totalPage;
        /// <summary>
        /// 总页数
        /// </summary>
        public int TotalPage { get => _totalPage; set=>SetProperty(ref _totalPage, value); }

        private int _entryAmount;
        /// <summary>
        /// 条目总数
        /// </summary>
        public int EntryAmount { get => _entryAmount; set=>SetProperty(ref _entryAmount, value); }

        /// <summary>
        /// 第一页命令
        /// </summary>
        public FirstPageCommand FirstPageCommand { get; } = new();
        /// <summary>
        /// 上一页命令
        /// </summary>
        public PrePageCommand PrePageCommand { get; } = new();
        /// <summary>
        /// 下一页命令
        /// </summary>
        public NextPageCommand NextPageCommand { get; } = new();
        /// <summary>
        /// 末页命令
        /// </summary>
        public LastPageCommand LastPageCommand { get; } = new();

        internal void RaiseCommandsCanExecute()
        {
            FirstPageCommand.OnCanExecuteChanged();
            PrePageCommand.OnCanExecuteChanged();
            NextPageCommand.OnCanExecuteChanged();
            LastPageCommand.OnCanExecuteChanged();
        }
    }
}
